from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-31 14:13:03.634918
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 31, Aug, 2021
Time: 14:13:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9067
Nobs: 400.000 HQIC: -46.4492
Log likelihood: 4342.79 FPE: 4.70941e-21
AIC: -46.8048 Det(Omega_mle): 3.77096e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.434865 0.094609 4.596 0.000
L1.Burgenland 0.103790 0.048834 2.125 0.034
L1.Kärnten -0.115424 0.024292 -4.752 0.000
L1.Niederösterreich 0.156684 0.105027 1.492 0.136
L1.Oberösterreich 0.137841 0.103240 1.335 0.182
L1.Salzburg 0.283549 0.051208 5.537 0.000
L1.Steiermark 0.025354 0.067818 0.374 0.709
L1.Tirol 0.108965 0.053638 2.031 0.042
L1.Vorarlberg -0.117496 0.048414 -2.427 0.015
L1.Wien -0.011077 0.093432 -0.119 0.906
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.019155 0.219705 0.087 0.931
L1.Burgenland -0.049013 0.113404 -0.432 0.666
L1.Kärnten 0.035348 0.056411 0.627 0.531
L1.Niederösterreich -0.245566 0.243900 -1.007 0.314
L1.Oberösterreich 0.518093 0.239750 2.161 0.031
L1.Salzburg 0.308805 0.118917 2.597 0.009
L1.Steiermark 0.115618 0.157490 0.734 0.463
L1.Tirol 0.312427 0.124561 2.508 0.012
L1.Vorarlberg -0.006401 0.112429 -0.057 0.955
L1.Wien 0.002889 0.216972 0.013 0.989
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.255208 0.048228 5.292 0.000
L1.Burgenland 0.086477 0.024894 3.474 0.001
L1.Kärnten -0.002105 0.012383 -0.170 0.865
L1.Niederösterreich 0.208553 0.053539 3.895 0.000
L1.Oberösterreich 0.169893 0.052628 3.228 0.001
L1.Salzburg 0.037816 0.026104 1.449 0.147
L1.Steiermark 0.016973 0.034571 0.491 0.623
L1.Tirol 0.062556 0.027343 2.288 0.022
L1.Vorarlberg 0.060007 0.024679 2.431 0.015
L1.Wien 0.105700 0.047628 2.219 0.026
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179808 0.046988 3.827 0.000
L1.Burgenland 0.047374 0.024253 1.953 0.051
L1.Kärnten -0.007233 0.012065 -0.600 0.549
L1.Niederösterreich 0.137705 0.052162 2.640 0.008
L1.Oberösterreich 0.318808 0.051275 6.218 0.000
L1.Salzburg 0.098906 0.025432 3.889 0.000
L1.Steiermark 0.133549 0.033682 3.965 0.000
L1.Tirol 0.076703 0.026640 2.879 0.004
L1.Vorarlberg 0.053783 0.024045 2.237 0.025
L1.Wien -0.039680 0.046403 -0.855 0.392
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208570 0.093709 2.226 0.026
L1.Burgenland -0.059386 0.048369 -1.228 0.220
L1.Kärnten -0.034933 0.024061 -1.452 0.147
L1.Niederösterreich 0.120531 0.104029 1.159 0.247
L1.Oberösterreich 0.178091 0.102259 1.742 0.082
L1.Salzburg 0.257544 0.050721 5.078 0.000
L1.Steiermark 0.078596 0.067173 1.170 0.242
L1.Tirol 0.121875 0.053128 2.294 0.022
L1.Vorarlberg 0.111026 0.047953 2.315 0.021
L1.Wien 0.022423 0.092544 0.242 0.809
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025804 0.072908 0.354 0.723
L1.Burgenland 0.026483 0.037632 0.704 0.482
L1.Kärnten 0.052190 0.018720 2.788 0.005
L1.Niederösterreich 0.212299 0.080937 2.623 0.009
L1.Oberösterreich 0.336320 0.079559 4.227 0.000
L1.Salzburg 0.045015 0.039462 1.141 0.254
L1.Steiermark -0.002773 0.052262 -0.053 0.958
L1.Tirol 0.113560 0.041335 2.747 0.006
L1.Vorarlberg 0.062982 0.037309 1.688 0.091
L1.Wien 0.129137 0.072001 1.794 0.073
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188094 0.088769 2.119 0.034
L1.Burgenland 0.020202 0.045819 0.441 0.659
L1.Kärnten -0.059956 0.022792 -2.631 0.009
L1.Niederösterreich -0.134482 0.098544 -1.365 0.172
L1.Oberösterreich 0.198228 0.096867 2.046 0.041
L1.Salzburg 0.027919 0.048047 0.581 0.561
L1.Steiermark 0.303820 0.063631 4.775 0.000
L1.Tirol 0.490505 0.050327 9.746 0.000
L1.Vorarlberg 0.069316 0.045425 1.526 0.127
L1.Wien -0.100784 0.087664 -1.150 0.250
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162369 0.096762 1.678 0.093
L1.Burgenland -0.005670 0.049945 -0.114 0.910
L1.Kärnten 0.063108 0.024844 2.540 0.011
L1.Niederösterreich 0.197906 0.107418 1.842 0.065
L1.Oberösterreich -0.125604 0.105590 -1.190 0.234
L1.Salzburg 0.241471 0.052373 4.611 0.000
L1.Steiermark 0.154073 0.069361 2.221 0.026
L1.Tirol 0.052047 0.054859 0.949 0.343
L1.Vorarlberg 0.123660 0.049515 2.497 0.013
L1.Wien 0.139512 0.095558 1.460 0.144
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489145 0.052355 9.343 0.000
L1.Burgenland -0.011923 0.027024 -0.441 0.659
L1.Kärnten -0.010357 0.013443 -0.770 0.441
L1.Niederösterreich 0.204060 0.058120 3.511 0.000
L1.Oberösterreich 0.260836 0.057131 4.566 0.000
L1.Salzburg 0.022174 0.028338 0.782 0.434
L1.Steiermark -0.024582 0.037529 -0.655 0.512
L1.Tirol 0.070366 0.029682 2.371 0.018
L1.Vorarlberg 0.057516 0.026791 2.147 0.032
L1.Wien -0.054459 0.051704 -1.053 0.292
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018148 0.076227 0.135717 0.133109 0.040600 0.069015 0.000364 0.175010
Kärnten 0.018148 1.000000 -0.054940 0.128840 0.046225 0.071020 0.456633 -0.092993 0.094758
Niederösterreich 0.076227 -0.054940 1.000000 0.281575 0.083884 0.271776 0.014411 0.149694 0.247723
Oberösterreich 0.135717 0.128840 0.281575 1.000000 0.179531 0.287125 0.160223 0.113859 0.138986
Salzburg 0.133109 0.046225 0.083884 0.179531 1.000000 0.127858 0.057452 0.106520 0.051366
Steiermark 0.040600 0.071020 0.271776 0.287125 0.127858 1.000000 0.130448 0.088344 -0.025396
Tirol 0.069015 0.456633 0.014411 0.160223 0.057452 0.130448 1.000000 0.042103 0.118282
Vorarlberg 0.000364 -0.092993 0.149694 0.113859 0.106520 0.088344 0.042103 1.000000 -0.048693
Wien 0.175010 0.094758 0.247723 0.138986 0.051366 -0.025396 0.118282 -0.048693 1.000000